﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;

namespace HDK.UI.Controls
{
    //public class PagingDecorator : Border
    //{
    //    #region Fields

    //    Size _availableSize;
    //    DispatcherTimer _resizeTimer;

    //    #endregion Fields

    //    #region Event Handlers

    //    void resizeTimer_Tick(object sender, EventArgs e)
    //    {
    //        _resizeTimer.Stop();
    //        GotoPage(this.CurrentPage);
    //    }

    //    #endregion Event Handlers

    //    #region Public Methods

    //    public void GotoPage(int pageIndex)
    //    {
    //        pageIndex = Math.Min(pageIndex, this.PageCount - 1);
    //        pageIndex = Math.Max(pageIndex, 0);

    //        this.CurrentPage = pageIndex;

    //        double offset = _availableSize.Width * pageIndex * -1;

    //        // construct an animation that will update the RenderTransform on the child

    //        TranslateTransform t = Child.RenderTransform as TranslateTransform;
    //        if (t == null)
    //        {
    //            t = new TranslateTransform();
    //            Child.RenderTransform = t;
    //        }

    //        DoubleAnimationUsingKeyFrames d = new DoubleAnimationUsingKeyFrames();
    //        SplineDoubleKeyFrame kf = new SplineDoubleKeyFrame();
    //        kf.
    //        //offset, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(this.TransitionDuration)));
    //        kf.KeySpline = this.TransitionKeySpline;
    //        d.KeyFrames.Add(kf);

    //        t.BeginAnimation(TranslateTransform.XProperty, d);
    //    }

    //    #endregion Public Methods

    //    #region Protected Methods

    //    protected override Size ArrangeOverride(Size finalSize)
    //    {
    //        // calculate the number of pages
    //        this.PageCount = (int)Math.Ceiling(Child.DesiredSize.Width / _availableSize.Width);

    //        Child.Arrange(new Rect(0, 0, Child.DesiredSize.Width, Child.DesiredSize.Height));

    //        if (_resizeTimer == null)
    //        {
    //            _resizeTimer = new DispatcherTimer();
    //            _resizeTimer.Interval = TimeSpan.FromMilliseconds(250);
    //            _resizeTimer.Tick += new EventHandler(resizeTimer_Tick);
    //        }
    //        _resizeTimer.Stop();
    //        _resizeTimer.Start();

    //        return _availableSize;
    //    }

    //    protected override Size MeasureOverride(Size availableSize)
    //    {
    //        _availableSize = availableSize;

    //        Child.Measure(new Size(double.PositiveInfinity, availableSize.Height));

    //        return Child.DesiredSize;
    //    }

    //    #endregion Protected Methods

    //    #region PageCount

    //    /// <summary>
    //    /// PageCount Dependency Property
    //    /// </summary>
    //    public static readonly DependencyProperty PageCountProperty =
    //        DependencyProperty.Register("PageCount", typeof(int), typeof(PagingDecorator),
    //            new FrameworkPropertyMetadata((int)-1,
    //                new PropertyChangedCallback(OnPageCountChanged)));

    //    /// <summary>
    //    /// Gets or sets the PageCount property.  This dependency property 
    //    /// indicates ....
    //    /// </summary>
    //    public int PageCount
    //    {
    //        get { return (int)GetValue(PageCountProperty); }
    //        set { SetValue(PageCountProperty, value); }
    //    }

    //    /// <summary>
    //    /// Handles changes to the PageCount property.
    //    /// </summary>
    //    private static void OnPageCountChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    //    {
    //        ((PagingDecorator)d).OnPageCountChanged(e);
    //    }

    //    /// <summary>
    //    /// Provides derived classes an opportunity to handle changes to the PageCount property.
    //    /// </summary>
    //    protected virtual void OnPageCountChanged(DependencyPropertyChangedEventArgs e)
    //    {
    //        int count = (int)e.NewValue;

    //        // update the collection
    //        if (this.PageCollection == null)
    //        {
    //            this.PageCollection = new ObservableCollection<NumberedPage>();
    //        }

    //        while (this.PageCollection.Count > count)
    //        {
    //            this.PageCollection.RemoveAt(this.PageCollection.Count - 1);
    //        }

    //        while (this.PageCollection.Count < count)
    //        {
    //            this.PageCollection.Add(new NumberedPage((count - (count - this.PageCollection.Count) + 1)));
    //        }

    //        this.CurrentPage = Math.Min(this.CurrentPage, count - 1);
    //    }

    //    #endregion

    //    #region TransitionKeySpline

    //    /// <summary>
    //    /// TransitionKeySpline Dependency Property
    //    /// </summary>
    //    public static readonly DependencyProperty TransitionKeySplineProperty =
    //        DependencyProperty.Register("TransitionKeySpline", typeof(KeySpline), typeof(PagingDecorator),
    //            new FrameworkPropertyMetadata((KeySpline)new KeySpline(0, 0.5, 0.5, 1)));

    //    /// <summary>
    //    /// Gets or sets the TransitionKeySpline property.  This dependency property 
    //    /// indicates ....
    //    /// </summary>
    //    public KeySpline TransitionKeySpline
    //    {
    //        get { return (KeySpline)GetValue(TransitionKeySplineProperty); }
    //        set { SetValue(TransitionKeySplineProperty, value); }
    //    }

    //    #endregion

    //    #region CurrentPage

    //    /// <summary>
    //    /// CurrentPage Dependency Property
    //    /// </summary>
    //    public static readonly DependencyProperty CurrentPageProperty =
    //        DependencyProperty.Register("CurrentPage", typeof(int), typeof(PagingDecorator),
    //            new FrameworkPropertyMetadata((int)0,
    //                new PropertyChangedCallback(OnCurrentPageChanged)));

    //    /// <summary>
    //    /// Gets or sets the CurrentPage property.  This dependency property 
    //    /// indicates ....
    //    /// </summary>
    //    public int CurrentPage
    //    {
    //        get { return (int)GetValue(CurrentPageProperty); }
    //        set { SetValue(CurrentPageProperty, value); }
    //    }

    //    /// <summary>
    //    /// Handles changes to the CurrentPage property.
    //    /// </summary>
    //    private static void OnCurrentPageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    //    {
    //        ((PagingDecorator)d).OnCurrentPageChanged(e);
    //    }

    //    /// <summary>
    //    /// Provides derived classes an opportunity to handle changes to the CurrentPage property.
    //    /// </summary>
    //    protected virtual void OnCurrentPageChanged(DependencyPropertyChangedEventArgs e)
    //    {
    //        this.GotoPage((int)e.NewValue);
    //    }

    //    #endregion

    //    #region PageCollection

    //    /// <summary>
    //    /// PageCollection Dependency Property
    //    /// </summary>
    //    public static readonly DependencyProperty PageCollectionProperty =
    //        DependencyProperty.Register("PageCollection", typeof(ObservableCollection<NumberedPage>), typeof(PagingDecorator),
    //            new FrameworkPropertyMetadata((ObservableCollection<NumberedPage>)null));

    //    /// <summary>
    //    /// Gets or sets the PageCollection property.  This dependency property 
    //    /// indicates ....
    //    /// </summary>
    //    public ObservableCollection<NumberedPage> PageCollection
    //    {
    //        get { return (ObservableCollection<NumberedPage>)GetValue(PageCollectionProperty); }
    //        set { SetValue(PageCollectionProperty, value); }
    //    }

    //    #endregion

    //    #region TransitionDuration

    //    /// <summary>
    //    /// TransitionDuration Dependency Property
    //    /// </summary>
    //    public static readonly DependencyProperty TransitionDurationProperty =
    //        DependencyProperty.Register("TransitionDuration", typeof(int), typeof(PagingDecorator),
    //            new FrameworkPropertyMetadata((int)600));

    //    /// <summary>
    //    /// Gets or sets the TransitionDuration property.  This dependency property 
    //    /// indicates ....
    //    /// </summary>
    //    public int TransitionDuration
    //    {
    //        get { return (int)GetValue(TransitionDurationProperty); }
    //        set { SetValue(TransitionDurationProperty, value); }
    //    }

    //    #endregion
    //}

    //public class NumberedPage
    //{
    //    public NumberedPage(int pageNumber)
    //    {
    //        PageNumber = pageNumber;
    //    }

    //    public int PageNumber { get; set; }
    //}
}
